﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.woodsoft.core;
using EQ1.Objects;
using com.woodsoft.core.Files;
using System.Xml;

namespace EQ1.Elements {
  public class TopLevelWindowList:UIClass, IUIElement<TopLevelWindowList> {
    public TopLevelWindowList ( UIDocument doc , string name ) : base( doc , name ) {
    }
    public TopLevelWindowList ( UIDocument doc )
      : this( doc , "TopLevelWindowList" ) {
    }

    #region IUIElement<TopLevelWindowList> Members

    public void Validate ( TopLevelWindowList val , string name ) {
      UIClass par = ( UIClass ) this.ParentNode;

      if( val.LocalName != name ) {
        TopLevelWindowList el = new TopLevelWindowList( ( UIDocument ) val.OwnerDocument , name );
        el.Copy( val );
        val = el;
      }

      if( par.GetElement( name ) != null )
        par.RemoveElement( name );

      par.AppendChild( val );
    }

    public void Copy ( TopLevelWindowList val ) {
      base.Copy( val );

      if( val.Screens != null )
        this.Screens = val.Screens;
    }

    #endregion
    /// <summary>
    /// Collection of <see cref="EQ1.Elements.Screens"/>
    /// </summary>
    public XmlNodeList Screens {
      get {
        return this.GetElementsByTagName( "Screens" );
      }
      set {
        foreach( Screens nd in value ) {
          if( nd.LocalName == "Screens" )
            this.AddScreen( nd );
        }
      }
    }
    public void AddScreen ( Screens val ) {
      for( int i = this.Screens.Count - 1 ; i >= 0 ; i-- ) {
        if( val.ScreenName == ((Screens)this.Screens[i]).ScreenName ) {
          this.ReplaceChild( val , this.Screens[i] );
          return;
        }        
      }

      this.AppendChild( val );
    }
    public Screens GetScreen ( string name ) {
      if(! string.IsNullOrEmpty( name ) ) {
        foreach( Screens nd in this.Screens ) {
          if( nd.ScreenName == name ) {
            return nd;
          }
        }
      }

      return null;
    }
  }
}
